//
//  YHMeCostSubItemCell.m
//  YHApp
//
//  Created by -- on 2021/7/23.
//

#import "HACostSubItemCell.h"
#import "HACostModel.h"

@interface HACostSubItemCell ()

/***/
@property (nonatomic, strong) UIButton *addButton;
/***/
@property (nonatomic, strong) UIButton *minusButton;
/***/
@property (nonatomic, strong) UILabel *numLabel;
/***/
@property (nonatomic, strong) UILabel *titLabel;

@end

@implementation HACostSubItemCell

-(void)setItemModel:(YHMeCostItemModel *)itemModel {
    _itemModel = itemModel;
    
    self.titLabel.text = _itemModel.label;
    
    self.numLabel.text = _itemModel.value;
}

-(void)layoutSubviews {
    [super layoutSubviews];
    
    [self.addButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-20);
        make.centerY.mas_equalTo(0);
        make.width.mas_offset(28);
        make.height.mas_offset(28);
    }];
    
    [self.numLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.addButton.mas_left).offset(-4);
        make.centerY.mas_equalTo(0);
        make.width.mas_offset(80);
        make.height.mas_offset(28);
    }];
    
    [self.minusButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.numLabel.mas_left).offset(-4);
        make.centerY.mas_equalTo(0);
        make.width.mas_offset(28);
        make.height.mas_offset(28);
    }];

    [self.titLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.centerY.mas_equalTo(0);
        make.right.mas_equalTo(self.minusButton.mas_left).offset(-10);
    }];

}

- (UIButton *)addButton
{
    if (!_addButton) {
        _addButton = [[UIButton alloc]init];
        [_addButton setTitle:@"+" forState:UIControlStateNormal];
        [_addButton setTitleColor:[UIColor colorWithHexString:@"#858B9C"] forState:UIControlStateNormal];
        _addButton.titleLabel.font = [UIFont systemFontOfSize:12];
        _addButton.backgroundColor = [UIColor colorWithHexString:@"#F9FAFB"];
        _addButton.layer.cornerRadius = 4;
        _addButton.layer.masksToBounds = YES;
        [self.contentView addSubview:_addButton];
    }
    return _addButton;
}

- (UIButton *)minusButton
{
    if (!_minusButton) {
        _minusButton = [[UIButton alloc]init];
        [_minusButton setTitle:@"-" forState:UIControlStateNormal];
        [_minusButton setTitleColor:[UIColor colorWithHexString:@"#858B9C"] forState:UIControlStateNormal];
        _minusButton.titleLabel.font = [UIFont systemFontOfSize:14];
        _minusButton.backgroundColor = [UIColor colorWithHexString:@"#F9FAFB"];
        _minusButton.layer.cornerRadius = 4;
        _minusButton.layer.masksToBounds = YES;
        [self.contentView addSubview:_minusButton];
    }
    return _minusButton;
}

- (UILabel *)numLabel
{
    if (!_numLabel) {
        _numLabel = [UILabel ha_NLabelWithFont:14 textColor:@"#858B9C" text:@"" alignment:1];
        _numLabel.backgroundColor = [UIColor colorWithHexString:@"#F9FAFB"];
        _numLabel.layer.cornerRadius = 4;
        _numLabel.layer.masksToBounds = YES;
        [self.contentView addSubview:_numLabel];
    }
    return _numLabel;
}

- (UILabel *)titLabel
{
    if (!_titLabel) {
        _titLabel = [UILabel ha_NLabelWithFont:18 textColor:@"#000000" text:@"" alignment:0];
        [self.contentView addSubview:_titLabel];
    }
    return _titLabel;
}

@end
